package com.ztesoft.huangfu.learning.springboot.springboottransaction.controller;


import com.ztesoft.huangfu.learning.springboot.springboottransaction.entity.Role;
import com.ztesoft.huangfu.learning.springboot.springboottransaction.service.RoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/5/24
 * Time: 19:55
 * Version: 1.0
 * Description: 使用自动mybaties自动生成工具生成
 **/
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @ApiOperation(value = "获取角色列表", notes = "获取所有角色")
    @GetMapping("/getAllRole")
    public List<Role> getAllRole() {
        return roleService.selectAllRole();
    }

    @ApiOperation(value = "根据Id获取角色")
    @GetMapping("/selectRoleByKey")
    public Role selectRoleByKey(String id) {
        return roleService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "删除角色")
    @DeleteMapping("/delete")
    public int deleteByPrimaryKey(String id) {
        return roleService.deleteByPrimaryKey(id);
    }

    @ApiOperation(value = "新增角色")
    @PostMapping("/insert")
    public int insert(Role role) {
        return roleService.insert(role);
    }

    @ApiOperation(value = "修改角色")
    @PostMapping("/update")
    public int update(Role role) {
        return roleService.updateByPrimaryKey(role);
    }

}
